package control;

import java.util.ArrayList;

/**
 * Fibonacci sequence is the sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, 
 * and so on, where each number (from the third on) is the sum of the previous 
 * two. Create a method that takes an integer as an argument and displays that 
 * many Fibonacci numbers starting from the beginning, e.g., 
 * If you run java Fibonacci 5 (where Fibonacci is the name of the class) 
 * the output will be: 1, 1, 2, 3, 5.
 * */

public class Ex9 {

	public static void main(String[] args) {
		ArrayList<Integer> lista = new ArrayList<Integer>();
		int n1 = 0; int n2 = 1; int cateNumere = 0;
		if (args.length!=0 ){
			cateNumere = Integer.parseInt(args[0]);
		}
		else cateNumere = 5;
		for (int i = 1;i<=cateNumere;i++){
			n1 = n1 + n2; //=1 =1 =2 =3 =5
			//System.out.println("iteratia " + i + " n1 = " + n1 + " si n1-n2= "+ (n1-n2));
			n2 = n1 - n2; //=0 =1 =1 =2 =3
			//System.out.println("iteratia " + i + " n2 = " + n2);
			lista.add(n1);
		}
		
		for (int i : lista){
		 System.out.print(i+",");
		}
	}
}









